home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Draw / Sources / BaseShp.cpp next >
Encoding:
Text File  |  1996-12-16  |  27.7 KB  |  1,008 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                BaseShp.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef UTILS_H
  19. #include "Utils.h"
  20. #endif
  21.  
  22. #ifndef CONSTANT_H
  23. #include "Constant.h"
  24. #endif
  25.  
  26. #ifndef DEFINES_K
  27. #include "Defines.k"
  28. #endif
  29.  
  30. #ifndef DRAWCONT_H
  31. #include "DrawCont.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWAPLEVT_H
  61. #include "FWAplEvt.h"
  62. #endif
  63.  
  64. #ifndef FWFRMING_H
  65. #include "FWFrming.h"
  66. #endif
  67.  
  68. #ifndef FWUTIL_H
  69. #include "FWUtil.h"
  70. #endif
  71.  
  72. #ifndef FWSELECT_H
  73. #include "FWSelect.h"
  74. #endif
  75.  
  76. #ifndef FWITERS_H
  77. #include "FWIters.h"
  78. #endif
  79.  
  80. #ifndef FWINTER_H
  81. #include "FWInter.h"
  82. #endif
  83.  
  84. #ifndef FWPRMISE_H
  85. #include "FWPrmise.h"
  86. #endif
  87.  
  88. #ifndef FWDSCOPR_H
  89. #include "FWDscOpr.h"
  90. #endif
  91.  
  92. #ifndef FWSEMTRM_H
  93. #include "FWSemTrm.h"
  94. #endif
  95.  
  96. // ----- OS Layer -----
  97.  
  98. #ifndef FWACQUIR_H
  99. #include "FWAcquir.h"
  100. #endif
  101.  
  102. #ifndef FWEVENT_H
  103. #include "FWEvent.h"
  104. #endif
  105.  
  106. #ifndef FWRECSHP_H
  107. #include "FWRecShp.h"
  108. #endif
  109.  
  110. #ifndef FWTXTBOX_H
  111. #include "FWTxtBox.h"
  112. #endif
  113.  
  114. #ifndef FWLINSHP_H
  115. #include "FWLinShp.h"
  116. #endif
  117.  
  118. #ifndef FWOVLSHP_H
  119. #include "FWOvlShp.h"
  120. #endif
  121.  
  122. #ifndef FWRRCSHP_H
  123. #include "FWRRcShp.h"
  124. #endif
  125.  
  126. #ifndef FWODGEOM_H
  127. #include "FWODGeom.h"
  128. #endif
  129.  
  130. #ifndef FWCFMRES_H
  131. #include "FWCFMRes.h"
  132. #endif
  133.  
  134. #ifndef FWRESACC_H
  135. #include "FWResAcc.h"
  136. #endif
  137.  
  138. #ifndef FWRESTYP_H
  139. #include "FWResTyp.h"
  140. #endif
  141.  
  142. // ----- Foundation Includes -----
  143.  
  144. #ifndef FWSTREAM_H
  145. #include "FWStream.h"
  146. #endif
  147.  
  148. #ifndef FWSOMENV_H
  149. #include "FWSOMEnv.h"
  150. #endif
  151.  
  152. // ----- OpenDoc Includes -----
  153.  
  154. #ifndef SOM_ODTransform_xh
  155. #include <Trnsform.xh>
  156. #endif
  157.  
  158. //========================================================================================
  159. // Runtime Information
  160. //========================================================================================
  161.  
  162. #ifdef FW_BUILD_MAC
  163. #pragma segment odfdrawshapes
  164. #endif
  165.  
  166. //========================================================================================
  167. //    Template instantiations
  168. //========================================================================================
  169.  
  170. #include "FWTRCtCl.tpp"
  171.  
  172. FW_DEFINE_AUTO_TEMPLATE(FW_TRefCountedCollection, CBaseShape)
  173. FW_DEFINE_AUTO_TEMPLATE(FW_TRefCountedCollectionIterator, CBaseShape)
  174.  
  175. #if FW_USE_TEMPLATE_PRAGMAS
  176. #pragma template_access public
  177. #pragma template FW_TRefCountedCollection<CBaseShape>
  178. #pragma template FW_TRefCountedCollectionIterator<CBaseShape>
  179. #endif
  180.  
  181. #if FW_ANSI_TEMPLATE_INSTANTIATION
  182. template class FW_TRefCountedCollection<CBaseShape>;
  183. template class FW_TRefCountedCollectionIterator<CBaseShape>;
  184. #endif
  185.  
  186. //========================================================================================
  187. // RunTime Info
  188. //========================================================================================
  189.  
  190. FW_DEFINE_AUTO(CBaseShape)
  191. FW_DEFINE_CLASS_M1(CBaseShape, FW_MScriptable)
  192.  
  193. const FW_ClassTypeConstant LBaseShape = FW_TYPE_CONSTANT('s','h','b','a');
  194. FW_REGISTER_ARCHIVABLE_CLASS(LBaseShape, CBaseShape, CBaseShape::Read, 0, 0, CBaseShape::Write)
  195.  
  196. //========================================================================================
  197. // globals
  198. //========================================================================================
  199.  
  200. FW_CRectShape* CBaseShape::gWorkingHandle = NULL;
  201. unsigned long CBaseShape::gShapeCount = 0;
  202.  
  203. // [KVV] Constructing gDefaultStyle and gDefaultInk like this causes
  204. //    problems because of order of initialization
  205. // const FW_CStyle gDefaultStyle = FW_kNormalStyle;
  206. // const FW_CInk gDefaultInk = FW_kNormalInk;
  207.  
  208. const FW_EStandardStyles gDefaultStyle = FW_kNormalStyle;
  209. const FW_EStandardInks gDefaultInk = FW_kNormalInk;
  210.  
  211. //========================================================================================
  212. // class CBaseShape
  213. //========================================================================================
  214.  
  215. //----------------------------------------------------------------------------------------
  216. // CBaseShape::CBaseShape
  217. //----------------------------------------------------------------------------------------
  218.  
  219. CBaseShape::CBaseShape(CDrawPart* drawPart, 
  220.                         short numberOfHandles, 
  221.                        unsigned short shapeType, 
  222.                        unsigned short renderVerb) :
  223.     FW_MScriptable(),
  224.     fDrawPart(drawPart),
  225.     fSelected(FALSE),
  226.     fNumberOfHandles(numberOfHandles),
  227.     fShapeType(shapeType),
  228.     fPublishLink(NULL),
  229.     fSubscribeLink(NULL),
  230.     fRenderVerb(renderVerb),
  231.     fFrameInk(gDefaultInk),
  232.     fFillInk(gDefaultInk),
  233.     fFrameStyle(gDefaultStyle),
  234.     fFillStyle(gDefaultStyle),
  235.     fPromised(0),
  236.     fExternalizationIndex(0),
  237.     fClipShape(NULL),
  238.     fGroup(NULL)
  239. {
  240.     InitStatic();
  241.     FW_END_CONSTRUCTOR
  242. }
  243.  
  244. //----------------------------------------------------------------------------------------
  245. // CBaseShape::CBaseShape
  246. //----------------------------------------------------------------------------------------
  247.  
  248. CBaseShape::CBaseShape(CDrawPart* drawPart, FW_CReadableStream& archive) :
  249.     FW_MScriptable(),
  250.     fDrawPart(drawPart),
  251.     fPublishLink(NULL),
  252.     fSubscribeLink(NULL),
  253.     fSelected(FALSE),
  254.     fPromised(0),
  255.     fExternalizationIndex(0),
  256.     fClipShape(NULL),
  257.     fGroup(NULL)
  258. {
  259.     InitStatic();
  260.     
  261.     archive >> fShapeType;
  262.     archive >> fNumberOfHandles;
  263.         
  264.     archive >> fFrameInk;
  265.     archive >> fFillInk;
  266.     archive >> fFrameStyle;
  267.     archive >> fFillStyle;
  268.  
  269.     archive >> fRenderVerb;
  270.     FW_END_CONSTRUCTOR
  271. }
  272.  
  273. //----------------------------------------------------------------------------------------
  274. // CBaseShape::InitStatic
  275. //----------------------------------------------------------------------------------------
  276.  
  277. void CBaseShape::InitStatic()
  278. {
  279.     if (gShapeCount == 0)
  280.     {
  281.         CBaseShape::gWorkingHandle = FW_NEW(FW_CRectShape, (FW_kZeroRect, FW_kFill));
  282.         CBaseShape::gWorkingHandle->SetInk(FW_kInvertInk);
  283.     }
  284.     
  285.     CBaseShape::gShapeCount++;
  286. }
  287.  
  288. //----------------------------------------------------------------------------------------
  289. // CBaseShape::~CBaseShape
  290. //----------------------------------------------------------------------------------------
  291.  
  292. CBaseShape::~CBaseShape()
  293. {
  294.     FW_START_DESTRUCTOR
  295.     FW_ASSERT(fPromised == 0);    // I should have resolved all my promises
  296.     FW_ASSERT(this->GetRefCount() == 0);  // Make sure we found all the old 'delete shape' etc.
  297.     
  298.     if (fClipShape)
  299.     {
  300.         FW_SOMEnvironment ev;
  301.         fClipShape->Release(ev);
  302.     }
  303.         
  304.     CBaseShape::gShapeCount--;
  305.     if (CBaseShape::gShapeCount == 0)
  306.         delete CBaseShape::gWorkingHandle;
  307. }
  308.  
  309. //----------------------------------------------------------------------------------------
  310. // CBaseShape::Removed
  311. //----------------------------------------------------------------------------------------
  312.  
  313. void CBaseShape::Removed(Environment* ev)
  314. {
  315. FW_UNUSED(ev);
  316. }
  317.  
  318. //----------------------------------------------------------------------------------------
  319. // CBaseShape::Deleted
  320. //----------------------------------------------------------------------------------------
  321.  
  322. void CBaseShape::Deleted(Environment* ev)
  323. {
  324. FW_UNUSED(ev);
  325. }
  326.  
  327. //----------------------------------------------------------------------------------------
  328. // CBaseShape::CheckPromise
  329. //----------------------------------------------------------------------------------------
  330.  
  331. void CBaseShape::CheckPromise(Environment* ev)
  332. {
  333.     
  334.     if (fPromised & FW_kClipboardStorage)
  335.         fDrawPart->GetDataInterchange(ev)->ResolveClipboardPromise(ev);
  336.     FW_ASSERT((fPromised & FW_kClipboardStorage) == 0);        // because CBaseShape::Promised should have been called
  337.  
  338. }
  339.  
  340. //----------------------------------------------------------------------------------------
  341. // CBaseShape::Promised
  342. //----------------------------------------------------------------------------------------
  343.  
  344. void CBaseShape::Promised(FW_StorageKinds storageKind, FW_Boolean state)
  345. {
  346.     if (state)
  347.         fPromised |= storageKind;
  348.     else
  349.         fPromised ^= fPromised & storageKind;
  350. }
  351.  
  352. //----------------------------------------------------------------------------------------
  353. // CBaseShape::TrackFeedback
  354. //----------------------------------------------------------------------------------------
  355.  
  356. void CBaseShape::TrackFeedback(Environment* ev,
  357.                                 ODFacet* facet,
  358.                                 FW_CGraphicContext& gc,
  359.                                 const FW_CPoint& anchorPoint, 
  360.                                 const FW_CPoint& currentPoint, 
  361.                                 FW_Boolean erase)
  362. {
  363.     if (!erase)
  364.         SetShapeGeometry(anchorPoint, currentPoint);
  365.  
  366.     RenderShape(ev, facet, gc);
  367. }
  368.  
  369. //----------------------------------------------------------------------------------------
  370. // CBaseShape::SelectShape
  371. //----------------------------------------------------------------------------------------
  372.  
  373. void CBaseShape::SelectShape(Environment* ev, FW_Boolean state)
  374. {
  375. FW_UNUSED(ev);
  376.     fSelected = state;
  377. }
  378.  
  379. //----------------------------------------------------------------------------------------
  380. // CBaseShape::ClearCache
  381. //----------------------------------------------------------------------------------------
  382.  
  383. void CBaseShape::ClearCache(Environment* ev)
  384. {
  385.     if (fClipShape)
  386.     {
  387.         fClipShape->Release(ev);
  388.         fClipShape = NULL;
  389.     }
  390. }
  391.  
  392. //----------------------------------------------------------------------------------------
  393. // CBaseShape::Invalidate
  394. //----------------------------------------------------------------------------------------
  395.  
  396. void CBaseShape::Invalidate(Environment* ev)
  397. {
  398.     fDrawPart->GetDrawContent()->RedrawShape(ev, this);
  399. }
  400.  
  401. //----------------------------------------------------------------------------------------
  402. // CBaseShape::RenderHandles
  403. //----------------------------------------------------------------------------------------
  404.  
  405. void CBaseShape::RenderHandles(FW_CGraphicContext& gc, FW_Fixed zoomFactor)
  406. {    
  407.     FW_Fixed penSize = CalcHandlePenSize(zoomFactor);
  408.     for (short i=1; i<=fNumberOfHandles; i++)
  409.     {
  410.         CalcHandle(i, CBaseShape::gWorkingHandle, penSize);    
  411.         CBaseShape::gWorkingHandle->Render(gc);
  412.     }
  413. }
  414.  
  415. //----------------------------------------------------------------------------------------
  416. // CBaseShape::InvalidateHandles
  417. //----------------------------------------------------------------------------------------
  418.  
  419. void CBaseShape::InvalidateHandles(Environment* ev, FW_CView* contentView, ODShape* workingShape, FW_Fixed penSize)
  420. {    
  421.     FW_CRect rect;
  422.     for (short i=1; i<=fNumberOfHandles; i++)
  423.     {
  424.         CalcHandle(i, rect, penSize);    
  425.         workingShape->SetRectangle(ev, rect);
  426.         contentView->Invalidate(ev, workingShape);
  427.     }
  428. }
  429.  
  430. //----------------------------------------------------------------------------------------
  431. // CBaseShape::CalcHandle
  432. //----------------------------------------------------------------------------------------
  433.  
  434. void CBaseShape::CalcHandle(short whichHandle, FW_CRectShape* handle, FW_Fixed penSize) const
  435. {
  436.     FW_CRect rect;
  437.     CalcHandle(whichHandle, rect, penSize);
  438.     handle->SetRectangle(rect);
  439. }
  440.  
  441. //----------------------------------------------------------------------------------------
  442. // CBaseShape::CalcHandle
  443. //----------------------------------------------------------------------------------------
  444.  
  445. void CBaseShape::CalcHandle(short whichHandle, FW_CRect& rect, FW_Fixed penSize) const
  446. {
  447.     FW_CPoint pt;
  448.     GetHandleCenter(whichHandle, pt);
  449.     rect.Set(pt.x - penSize, pt.y - penSize, pt.x + penSize, pt.y + penSize);
  450. }
  451.  
  452. //----------------------------------------------------------------------------------------
  453. // CBaseShape::InSelectionRect
  454. //----------------------------------------------------------------------------------------
  455.  
  456. FW_Boolean CBaseShape::InSelectionRect(const FW_CRect& selectRect) const
  457. {
  458.     FW_CRect bounds = GetRectGeometry();
  459.     
  460.     FW_CRect temp(bounds);
  461.     temp.Intersection(selectRect);
  462.     
  463.     return bounds == temp;
  464. }
  465.  
  466. //----------------------------------------------------------------------------------------
  467. // CBaseShape::Flatten
  468. //----------------------------------------------------------------------------------------
  469.  
  470. void CBaseShape::Flatten(FW_CWritableStream& archive)
  471. {    
  472.     archive << fShapeType;
  473.     archive << fNumberOfHandles;
  474.     
  475.     archive << fFrameInk;
  476.     archive << fFillInk;
  477.     archive << fFrameStyle;
  478.     archive << fFillStyle;
  479.     
  480.     archive << fRenderVerb;
  481. }
  482.  
  483. //----------------------------------------------------------------------------------------
  484. // CBaseShape::RestoreShape
  485. //----------------------------------------------------------------------------------------
  486.  
  487. void CBaseShape::RestoreShape(Environment *ev)
  488. {
  489.     if(fShapeType == kGroupShape || fSubscribeLink == NULL)
  490.         fDrawPart->AddShapeToPart(ev, this);
  491. }
  492.  
  493. //----------------------------------------------------------------------------------------
  494. // CBaseShape::SetFrozen
  495. //----------------------------------------------------------------------------------------
  496.  
  497. FW_Boolean CBaseShape::SetFrozen(FW_Boolean state)
  498. {
  499. FW_UNUSED(state);
  500.     return FALSE;    // Means I don't care
  501. }
  502.  
  503. //----------------------------------------------------------------------------------------
  504. // CBaseShape::IsFrozen
  505. //----------------------------------------------------------------------------------------
  506.  
  507. FW_Boolean CBaseShape::IsFrozen() const
  508. {
  509.     return FALSE;
  510. }
  511.  
  512. //----------------------------------------------------------------------------------------
  513. // CBaseShape::GetPenSize
  514. //----------------------------------------------------------------------------------------
  515.  
  516. FW_Fixed CBaseShape::GetPenSize() const
  517. {
  518.     return HasFrameStyle() ? fFrameStyle.GetPenSize() : FW_kFixed0;
  519. }
  520.  
  521. //----------------------------------------------------------------------------------------
  522. // CBaseShape::GetColor
  523. //----------------------------------------------------------------------------------------
  524. void CBaseShape::GetColor(FW_Boolean fill, FW_CColor& color)
  525. {
  526.     if (fill)
  527.         fFillInk.GetForeColor(color);
  528.     else
  529.         fFrameInk.GetForeColor(color);
  530. }
  531.  
  532. //----------------------------------------------------------------------------------------
  533. // CBaseShape::GetPattern
  534. //----------------------------------------------------------------------------------------
  535. FW_CPattern CBaseShape::GetPattern(FW_Boolean fill)
  536. {
  537.     if (fill)
  538.         return fFillStyle.GetPattern();
  539.     else
  540.         return fFrameStyle.GetPattern();
  541. }
  542.  
  543. //----------------------------------------------------------------------------------------
  544. // CBaseShape::UnshareInk
  545. //----------------------------------------------------------------------------------------
  546.  
  547. FW_CInk CBaseShape::UnshareInk(const FW_CInk& ink) const
  548. {
  549. //    Do not use the following syntax. It looks like the life time of temporaries
  550. //    is wrong causing a bad refcounting problem
  551. //    return (ink->GetRefCount() > 1) ? ink->Copy() : ink;
  552.  
  553.     if (ink.GetRefCount() > 1)
  554.         return ink.Copy();
  555.     else
  556.         return ink;
  557. }
  558.  
  559. //----------------------------------------------------------------------------------------
  560. // CBaseShape::UnshareStyle
  561. //----------------------------------------------------------------------------------------
  562.  
  563. FW_CStyle CBaseShape::UnshareStyle(const FW_CStyle& style) const
  564. {
  565. //    Do not use the following syntax. It looks like the life time of temporaries
  566. //    is wrong causing a bad refcounting problem
  567. //    return (style->GetRefCount() > 1) ? style->Copy() : style;
  568.  
  569.     if (style.GetRefCount() > 1)
  570.         return style.Copy();
  571.     else
  572.         return style;
  573. }
  574.  
  575. //----------------------------------------------------------------------------------------
  576. // CBaseShape::ChangeFrameColor
  577. //----------------------------------------------------------------------------------------
  578.  
  579. void CBaseShape::ChangeFrameColor(Environment* ev, const FW_CColor& color)
  580. {
  581.     if (HasFrameStyle())
  582.     {
  583.         CheckPromise(ev);
  584.         
  585.         fFrameInk = UnshareInk(fFrameInk);
  586.         fFrameInk.SetForeColor(color);
  587.     }
  588. }
  589.  
  590. //----------------------------------------------------------------------------------------
  591. // CBaseShape::ChangeFramePattern
  592. //----------------------------------------------------------------------------------------
  593.  
  594. void CBaseShape::ChangeFramePattern(Environment* ev, const FW_CPattern& pattern)
  595. {
  596.     if (HasFrameStyle())
  597.     {
  598.         CheckPromise(ev);
  599.         
  600.         fFrameStyle = UnshareStyle(fFrameStyle);
  601.         fFrameStyle.SetPattern(pattern);
  602.     }
  603. }
  604.  
  605. //----------------------------------------------------------------------------------------
  606. // CBaseShape::ChangeFillColor
  607. //----------------------------------------------------------------------------------------
  608.  
  609. void CBaseShape::ChangeFillColor(Environment* ev, const FW_CColor& color)
  610. {
  611.     if (HasFillStyle())
  612.     {
  613.         CheckPromise(ev);
  614.         
  615.         fFillInk = UnshareInk(fFillInk);
  616.         fFillInk.SetForeColor(color);
  617.     }
  618. }
  619.  
  620. //----------------------------------------------------------------------------------------
  621. // CBaseShape::ChangeFillPattern
  622. //----------------------------------------------------------------------------------------
  623.  
  624. void CBaseShape::ChangeFillPattern(Environment* ev, const FW_CPattern& pattern)
  625. {
  626.     if (HasFillStyle())
  627.     {
  628.         CheckPromise(ev);
  629.         
  630.         fFillStyle = UnshareStyle(fFillStyle);
  631.         fFillStyle.SetPattern(pattern);
  632.     }
  633. }
  634.  
  635. //----------------------------------------------------------------------------------------
  636. // CBaseShape::ChangePenSize
  637. //----------------------------------------------------------------------------------------
  638.  
  639. void CBaseShape::ChangePenSize(Environment* ev, FW_Fixed newPenSize)
  640. {
  641.     if (HasFrameStyle())
  642.     {
  643.         CheckPromise(ev);
  644.         
  645.         ClearCache(ev);
  646.         
  647.         fFrameStyle = UnshareStyle(fFrameStyle);
  648.         fFrameStyle.SetPenSize(newPenSize);
  649.     }
  650. }
  651.  
  652. //----------------------------------------------------------------------------------------
  653. // CBaseShape::SetSubscribeLink
  654. //----------------------------------------------------------------------------------------
  655.  
  656. void CBaseShape::SetSubscribeLink(Environment* ev, CDrawSubscribeLink *subscribeLink)
  657. {
  658. FW_UNUSED(ev);
  659.  
  660.     fSubscribeLink = subscribeLink;
  661. }
  662.  
  663. //----------------------------------------------------------------------------------------
  664. // CBaseShape::SetPublishLink
  665. //----------------------------------------------------------------------------------------
  666.  
  667. void CBaseShape::SetPublishLink(Environment* ev, CDrawPublishLink *publishLink)
  668. {
  669. FW_UNUSED(ev);
  670.  
  671.     fPublishLink = publishLink;
  672. }
  673.  
  674. //----------------------------------------------------------------------------------------
  675. // CBaseShape::AdjustRectForPenSize
  676. //----------------------------------------------------------------------------------------
  677.  
  678. void CBaseShape::AdjustRectForPenSize(FW_CRect& rect, FW_Fixed penSize) const
  679. {
  680.     FW_Fixed half = FW_Half(penSize);
  681.     rect.Inset(-half, -half);
  682. }
  683.  
  684. //----------------------------------------------------------------------------------------
  685. // CBaseShape::ChangeRenderVerb
  686. //----------------------------------------------------------------------------------------
  687.  
  688. void CBaseShape::ChangeRenderVerb(Environment* ev, unsigned short renderVerb)
  689. {
  690.     CheckPromise(ev);
  691.     
  692.     ClearCache(ev);
  693.     fRenderVerb = renderVerb;
  694. }
  695.  
  696. //----------------------------------------------------------------------------------------
  697. // CBaseShape::GetObjectClass
  698. //----------------------------------------------------------------------------------------
  699.  
  700. ODDescType CBaseShape::GetObjectClass() const
  701. {
  702.     return kShapeClass;
  703. }
  704.  
  705. //----------------------------------------------------------------------------------------
  706. // CBaseShape::AcquireScriptable
  707. //----------------------------------------------------------------------------------------
  708.  
  709. long CBaseShape::AcquireScriptable()
  710. {
  711.     return Acquire();
  712. }
  713.  
  714. //----------------------------------------------------------------------------------------
  715. // CBaseShape::ReleaseScriptable
  716. //----------------------------------------------------------------------------------------
  717.  
  718. long CBaseShape::ReleaseScriptable()
  719. {
  720.     return Release();
  721. }
  722.  
  723. //----------------------------------------------------------------------------------------
  724. // CBaseShape::HasProperty
  725. //----------------------------------------------------------------------------------------
  726.  
  727. FW_Boolean CBaseShape::HasProperty(ODDescType whichProperty) const
  728. {
  729.     FW_Boolean hasProperty;
  730.     
  731.     switch (whichProperty)
  732.     {
  733.         case pColor:
  734.         case pPosition:
  735.         case pIndex:
  736.             hasProperty = TRUE;
  737.             break;
  738.         
  739.         default:
  740.             hasProperty = FW_MScriptable::HasProperty(whichProperty);
  741.             break;
  742.     }
  743.     return hasProperty;
  744. }
  745.  
  746. //----------------------------------------------------------------------------------------
  747. // CBaseShape::GetProperty
  748. //----------------------------------------------------------------------------------------
  749.  
  750. FW_Boolean CBaseShape::GetProperty(Environment* ev,
  751.                                 FW_CPart* part,
  752.                                 FW_CDesc& propertyValue, 
  753.                                 ODDescType whichProperty,
  754.                                 ODDescType desiredType) const
  755. {
  756.     FW_Boolean result = TRUE;
  757.     
  758.     switch (whichProperty)
  759.     {            
  760.         case pColor:
  761.             {
  762.                 FW_CColor color = fFillInk.GetForeColor();
  763.                 propertyValue << color;
  764.             }
  765.             break;
  766.                         
  767.         case pPosition:
  768.             propertyValue << GetRectGeometry().TopLeft().AsPlatformPoint();
  769.             break;
  770.                         
  771.         default:
  772.             result = FW_MScriptable::GetProperty(ev, part, propertyValue, whichProperty, desiredType);
  773.             break;
  774.     }
  775.     
  776.     return result;
  777. }
  778.  
  779. //----------------------------------------------------------------------------------------
  780. // CBaseShape::SetProperty
  781. //----------------------------------------------------------------------------------------
  782.  
  783. void CBaseShape::SetProperty(Environment* ev,
  784.                             FW_CPart* part,
  785.                             FW_CDesc& propertyValue, 
  786.                             ODDescType whichProperty)
  787. {    
  788.     switch (whichProperty)
  789.     {
  790.         case pColor:
  791.             {
  792.                 if (HasFillStyle())
  793.                 {
  794.                     FW_CColor newColor;
  795.                     propertyValue >> newColor;
  796.         
  797.                     FW_CColor oldColor;
  798.                     GetColor(TRUE, oldColor);
  799.                     
  800.                     if (newColor != oldColor)
  801.                     {
  802.                         ChangeFillColor(ev, newColor);
  803.                         Invalidate(ev);
  804.                     }
  805.                 }
  806.             }
  807.             break;
  808.             
  809.         case pPosition:
  810.             {
  811.                 FW_CPoint     newPosition;
  812.                 FW_CRect    bounds = GetRectGeometry();
  813.                 
  814.                 propertyValue >> newPosition;
  815.                 
  816.                 Invalidate(ev);    // inval the old location            
  817.                 OffsetShape(ev, newPosition.x - bounds.left, newPosition.y - bounds.top);
  818.                 Invalidate(ev);    // inval the new location    
  819.             }
  820.             break;
  821.             
  822.         default:
  823.             FW_MScriptable::SetProperty(ev, part, propertyValue, whichProperty);
  824.             break;
  825.     }
  826. }
  827.  
  828. //----------------------------------------------------------------------------------------
  829. // CBaseShape::GetUndoStrings
  830. //----------------------------------------------------------------------------------------
  831.  
  832. void CBaseShape::GetUndoStrings(Environment* ev,
  833.                                 FW_CPart* part,
  834.                                 ODDescType whichProperty,
  835.                                 FW_CString& undoString,
  836.                                 FW_CString& redoString) const
  837. {
  838.     if (whichProperty == pColor)
  839.     {
  840.         FW_PSharedLibraryResourceFile resFile(ev);
  841.         ::FW_LoadStringByID(ev, resFile, kDrawUndoStrings, FW_kMultiStringRes, kUndoFillColorMsg, undoString);
  842.         ::FW_LoadStringByID(ev, resFile, kDrawUndoStrings, FW_kMultiStringRes, kRedoFillColorMsg, redoString);
  843.     }
  844.     else
  845.         FW_MScriptable::GetUndoStrings(ev, part, whichProperty, undoString, redoString);
  846. }
  847.  
  848. //----------------------------------------------------------------------------------------
  849. // CBaseShape::Read
  850. //----------------------------------------------------------------------------------------
  851.  
  852. void* CBaseShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  853. {
  854. FW_UNUSED(stream);
  855. FW_UNUSED(type);
  856.     FW_DEBUG_MESSAGE("CBaseShape::Read should never be called");
  857.     return NULL;
  858. }
  859.  
  860. //----------------------------------------------------------------------------------------
  861. // CBaseShape::Write
  862. //----------------------------------------------------------------------------------------
  863.  
  864. void CBaseShape::Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object)
  865. {
  866. FW_UNUSED(type);
  867.      ((CBaseShape*)object)->Flatten(stream);
  868. }
  869.  
  870. //----------------------------------------------------------------------------------------
  871. // CBaseShape::GetUpdateBox
  872. //----------------------------------------------------------------------------------------
  873.  
  874. void CBaseShape::GetUpdateBox(Environment* ev, ODShape* updateBox) const
  875. {
  876.     FW_CRect bounds = GetRectGeometry();    
  877.  
  878.     const FW_Fixed fxMargin = FW_IntToFixed(3);
  879.  
  880.     bounds.left        -= fxMargin;
  881.     bounds.top        -= fxMargin;
  882.     bounds.right    += fxMargin;
  883.     bounds.bottom    += fxMargin;
  884.  
  885.     ODRect odBounds = bounds;
  886.     updateBox->SetRectangle(ev, &odBounds);
  887. }
  888.  
  889. //----------------------------------------------------------------------------------------
  890. // CBaseShape::GetUpdateBox
  891. //----------------------------------------------------------------------------------------
  892.  
  893. void CBaseShape::GetUpdateBox(FW_CRect& updateBox) const
  894. {
  895.     updateBox = GetRectGeometry();
  896.  
  897.     const FW_Fixed fxMargin = FW_IntToFixed(3);
  898.  
  899.     updateBox.left        -= fxMargin;
  900.     updateBox.top        -= fxMargin;
  901.     updateBox.right        += fxMargin;
  902.     updateBox.bottom    += fxMargin;
  903. }
  904.  
  905. //----------------------------------------------------------------------------------------
  906. // CBaseShape::GetDragRect
  907. //----------------------------------------------------------------------------------------
  908.  
  909. void CBaseShape::GetDragRect(FW_CRect& dragRect) const
  910. {
  911.     dragRect = GetRectGeometry();
  912.     AdjustRectForPenSize(dragRect, GetPenSize());
  913. }
  914.  
  915. //----------------------------------------------------------------------------------------
  916. // CBaseShape::GetResizeStyle
  917. //----------------------------------------------------------------------------------------
  918.  
  919. FW_CStyle CBaseShape::GetResizeStyle() const
  920. {
  921.     FW_CStyle resizeStyle(GetPenSize(), FW_kGrayPat);
  922.     return resizeStyle;
  923. }
  924.  
  925. //----------------------------------------------------------------------------------------
  926. // CBaseShape::SubtractToWorkingClip
  927. //----------------------------------------------------------------------------------------
  928. //    ATTENTION: workingClip is in Content coordinates. tempShape is just a working shape. It is
  929. //    allocated by CDrawFrame::ClipEmbeddedFacets so I don't have to allocate one everytime.
  930.  
  931. void CBaseShape::SubtractToWorkingClip(Environment *ev, 
  932.                                         CDrawFacetClipper* facetClipper, 
  933.                                         ODFacet* containingFacet, 
  934.                                         ODShape* workingClip, 
  935.                                         ODShape* tempShape,
  936.                                         ODShape* limitShape)
  937. {
  938. FW_UNUSED(facetClipper);
  939. FW_UNUSED(containingFacet);
  940. FW_UNUSED(tempShape);
  941. FW_UNUSED(limitShape);
  942.  
  943.     FW_CAcquiredODShape clipShape = AcquireClipShape(ev);
  944.     clipShape->SetGeometryMode(ev, kODLoseGeometry);
  945.     workingClip->Subtract(ev, clipShape);
  946. }
  947.  
  948. //----------------------------------------------------------------------------------------
  949. // CBaseShape::WhichHandle
  950. //----------------------------------------------------------------------------------------
  951.  
  952. short CBaseShape::WhichHandle(FW_CGraphicContext& gc, const FW_CPoint& mouse, FW_Fixed zoomFactor) const
  953. {
  954.     FW_Fixed penSize = CalcHandlePenSize(zoomFactor);
  955.     for (short i=1; i<=fNumberOfHandles; i++)
  956.     {
  957.         CalcHandle(i, CBaseShape::gWorkingHandle, penSize);
  958.         if (CBaseShape::gWorkingHandle->HitTest(gc, mouse, FW_kFixed0))
  959.             return i;
  960.     }
  961.         
  962.     return 0;
  963. }
  964.  
  965. //----------------------------------------------------------------------------------------
  966. // CBaseShape::IsInLinkDestination
  967. //----------------------------------------------------------------------------------------
  968.  
  969. FW_Boolean CBaseShape::IsInLinkDestination(Environment* ev)
  970. {
  971. FW_UNUSED(ev);
  972.     return IsSubscribed();
  973. }
  974.  
  975. //----------------------------------------------------------------------------------------
  976. // CBaseShape::AcquireClipShape
  977. //----------------------------------------------------------------------------------------
  978.  
  979. ODShape* CBaseShape::AcquireClipShape(Environment* ev)
  980. {
  981.     if (fClipShape == NULL)
  982.         fClipShape = CalcClipShape(ev);
  983.     
  984.     fClipShape->Acquire(ev);
  985.     return fClipShape;
  986. }
  987.  
  988. //----------------------------------------------------------------------------------------
  989. // CBaseShape::MakePurgeable
  990. //----------------------------------------------------------------------------------------
  991.  
  992. void CBaseShape::MakePurgeable(Environment* ev, CDrawFrame* drawFrame, const FW_CRect& bounds)
  993. {
  994. FW_UNUSED(ev);
  995. FW_UNUSED(drawFrame);
  996. FW_UNUSED(bounds);
  997.     // Does nothing (see CProxyShape::MakePurgeable)
  998. }
  999.  
  1000. //----------------------------------------------------------------------------------------
  1001. // CBaseShape::ShapeCommitPasteDone
  1002. //----------------------------------------------------------------------------------------
  1003.  
  1004. void CBaseShape::ShapeCommitPasteDone(Environment* ev)
  1005. {
  1006.     FW_UNUSED(ev);
  1007. }
  1008.